import 'package:flutter/material.dart';
import 'package:getwidget/getwidget.dart';

class ItemVideo extends StatelessWidget {
  const ItemVideo({
    super.key,
    required this.title,
    required this.subtitle,
    required this.id,
    this.onTap,
    this.thumbnailUrl,
  });

  final String? id;
  final String? thumbnailUrl;
  final String title;
  final String subtitle;
  final void Function(String? id)? onTap;

  void handleTap() {
    final tapHandler = onTap;
    if (tapHandler != null) {
      tapHandler(id);
    }
  }

  /*   @override
  Widget build(BuildContext context) {
    return Card(
      child: ListTile(
        leading: thumbnailUrl != null ?
          Image.network(
            thumbnailUrl!,
            errorBuilder: (context, error, stackTrace) => SizedBox(
              width: 66,
              height: 100,
              child: Center(
                child: const Text('failed'),
              ),
            ),
            height: 100,
            width: 66)
          :
          null,
        title: Text(title),
        subtitle: Text(subtitle),
        onTap: handleTap,
      ),
    );
  } */

  @override
  Widget build(BuildContext context) {
    return GFListTile(
      titleText: title,
      subTitleText: subtitle,
      margin: EdgeInsets.only(bottom: 0),
      avatar: thumbnailUrl != null
          ? Image.network(
              thumbnailUrl!,
              errorBuilder: (context, error, stackTrace) => SizedBox(
                width: 66,
                height: 100,
                child: Center(child: const Text('failed')),
              ),
              height: 100,
              width: 66,
            )
          : null,
      onTap: handleTap,
    );
  }
}
